package com.monco.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.monco.entity.Dict;
import com.monco.mapper.DictMapper;
import com.monco.service.IDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author com/monco
 * @since 2020-04-19
 */
@Service
public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements IDictService {

    @Resource
    private DictMapper dictMapper;

    @Override
    public List<Dict> getDictList(Dict dict) {
        return dictMapper.selectList(getWrapper(dict));
    }

    @Override
    public IPage<Dict> getDictPage(IPage<Dict> page, Dict dict) {
        return dictMapper.selectPage(page, getWrapper(dict));
    }

    private QueryWrapper<Dict> getWrapper(Dict dict) {
        QueryWrapper<Dict> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(dict.getKeyCode())) {
            queryWrapper.eq("key_code", dict.getKeyCode());
        }
        return queryWrapper;
    }
}
